package etnorservice.etnor_service.controller;

import etnorservice.etnor_service.domain.po.Notice;
import etnorservice.etnor_service.result.Result;
import etnorservice.etnor_service.service.NoticeService;
import etnorservice.etnor_service.utils.AesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/06/30/14:49
 **/
@RestController
public class NoticeController {
    @Autowired
    NoticeService noticeService;
    @GetMapping("/announcements")
    public Result getNoticeCurrent() throws Exception {
        Result result = new Result();
        result.setCode(200);
        List<Notice> noticeCurrent = noticeService.getNoticeCurrent();
        for(Notice notice:noticeCurrent){
            notice.setId(AesUtil.encrypt(notice.getId()));
        }
        result.setData(noticeCurrent);
        return result;
    }
    @GetMapping("/announcements/detail/{id}")
    public Result getNoticeDetail(@PathVariable String id) throws Exception {
        Result result = new Result();

        result.setCode(200);
        String newId=AesUtil.decrypt(id);
        result.setData(noticeService.getNoticeDetail(newId));
        return result;
    }

}
